@extends('admin.layout')

@section('title', '提示')

@section('body')
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">参数设置</div>
                    <div class="layui-card-body layui-row">
                        <form class="layui-form layui-col-lg9">
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">博客名称</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="blog_name" value="{{ $blog_name }}" required lay-verify="required"
                                               placeholder="请输入内容" maxlength="20" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">博客标语</label>
                                <div class="layui-input-block">
                                    <input type="text" name="blog_tagline" value="{{ $blog_tagline }}" required lay-verify="required"
                                           placeholder="请输入内容" maxlength="100" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">博主名字</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="master_name" value="{{ $master_name }}" required
                                               lay-verify="required" maxlength="20" placeholder="请输入内容" autocomplete="off"
                                               class="layui-input">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">博主头像</label>
                                <div class="layui-input-block choose-master-avatar">
                                    <input type="text" name="master_avatar" value="{{ $master_avatar }}" required
                                           lay-verify="required" maxlength="100" placeholder="请输入内容" autocomplete="off" class="layui-input">
                                    <button type="button" class="layui-btn"><i class="layui-icon layui-icon-picture"></i>浏览服务器</button>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">博主简介</label>
                                <div class="layui-input-block">
                                    <textarea name="master_intro" required lay-verify="required" placeholder="请输入内容"
                                              maxlength="255" class="layui-textarea">{{ $master_intro }}</textarea>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">首页title</label>
                                <div class="layui-input-block">
                                    <input type="text" name="home_title" value="{{ $home_title }}" required lay-verify="required"
                                           placeholder="请输入内容" maxlength="50" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">首页keywords</label>
                                <div class="layui-input-block">
                                    <input type="text" name="home_keywords" value="{{ $home_keywords }}" required
                                           lay-verify="required" maxlength="150" placeholder="多个关键词用英文逗号分隔" autocomplete="off"
                                           class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">首页description</label>
                                <div class="layui-input-block">
                                    <textarea name="home_description" required lay-verify="required" placeholder="请输入内容"
                                              maxlength="255" class="layui-textarea">{{ $home_description }}</textarea>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">页脚内容</label>
                                <div class="layui-input-block">
                                    <textarea name="footer_content" rows="10" required lay-verify="required" placeholder="支持HTML代码"
                                              class="layui-textarea"
                                              style="font-family: Courier New; font-size: 13px">{{ $footer_content }}</textarea>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button type="submit" class="layui-btn" lay-submit="">提交</button>
                                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="/static/ckfinder/ckfinder.js"></script>
    <script>
        layui.use(['layer', 'form'], function () {
            var $ = layui.$;
            var layer = layui.layer;
            var form = layui.form;

            $('.choose-master-avatar .layui-btn').click(function () {
                CKFinder.popup({
                    chooseFiles: true,
                    width: 800,
                    height: 600,
                    onInit: function (finder) {
                        finder.on('files:choose', function (evt) {
                            var file = evt.data.files.first();
                            $('.choose-master-avatar .layui-input').val(file.getUrl());
                        });
                        finder.on('file:choose:resizedImage', function (evt) {
                            $('.choose-master-avatar .layui-input').val(evt.data.resizedUrl);
                        });
                    }
                });
            });

            form.on('submit', function (obj) {
                $.post('/admin/setting', obj.field, function (res) {
                    if (res.code === 0) {
                        layer.msg(res.msg, {
                            icon: 1,
                            time: 1000
                        });
                    } else {
                        layer.msg(res.msg, {icon: 5});
                    }
                }, 'json');
                return false;
            });
        });
    </script>
@endsection
